#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <boost/program_options.hpp>
#include <string>
#include <math.h>
#include "get_arg.h"


// link with -lboost_filesystem-gcc -lboost_program_options-gcc  -lboost_regex-gcc
// program_options_helper.cpp

// my functions
#define DEBUG_LEVEL 6
#include <debug_func.h>
#include <matrix_formats.h>
#include <print_error.h>
#include <program_options_helper.h>

using std::string;
using std::cerr;
using namespace program_options_helper;
namespace po = boost::program_options_lg;


bool process_command_line_options(int argc, char* argv[], t_program_args& args)
{

	// mandatory arguments
	//string matrix_file_name;
	//po::options_description mandatory_args("Mandatory Arguments");
	//mandatory_args.add_options()
	//("matrix_file,m", po::value<string>(&matrix_file_name)->set_name("FILE"),
	//								"Matrix data in the specified format");



	// optional arguments
	char output_format;
	args.optional_args.add_options()
	("output_format,o", po::value<char>(&output_format)->default_value('p')->set_name("FORMAT"),
									"Output FORMAT is binary ('b'), pairs ('p'), "
									"square ('s') or lower triangular ('l') .")
	("header,H",					"Add a header line (matrix name prefixed with '>') "
									"to the matrix output.")
	("alphabetic_order,a",			"Output names in alphabetical order");

	args.add_std_options();
	po::options_description all_args("");
	all_args.add(args.optional_args);

	// parse command line
	po::variables_map vm;
	po::store(po::command_line_parser(argc, argv).options(all_args).run(), vm);
	po::notify(vm);

	if (vm.count("version"))
	{
		print_version(cerr, *argv, "1.0\n"
			"\tHistory: \n\n"
			"\tv 1.0\1"
			"Initial version\n"
//			"\tv 1.1\1"
//			"01-02-2005\1"
//			"Split programme so that vanilla version does not do anything with matrices.\n"
			);
		return false;
	}
	if (vm.count("help"))
	{
		string exe_description =
			"Takes a tree in New Hamshire format "
		"from STDIN and outputs the corresponding matrix.\n\n";
		print_usage(cerr, string(*argv), "[OPTIONS] < TREE",
							all_args, exe_description, 80);
		return false;
	}

	args.header						= vm.count("header");
	args.alpha						= vm.count("alphabetic_order");


	select_matrix_file_format(output_format, args.output_format, "output format");

	args.open_err_log();
	return true;
}



